package service;

import java.util.List;

import common.PageReturn;
import dao.EssayMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import dao.EssayDao;
import pojo.EssayAndUser;
import pojo.Essay;
import pojo.Page;

@Service
public class EssayServiceImpl implements EssayServiceI
{

    @Autowired
    private EssayDao eDao;
    @Autowired
    private EssayMapper eMapper;

    @Override
    public List<EssayAndUser> ShowAllEssay() {
        // TODO Auto-generated method stub
        String permission = "B_all";
        return eDao.findalleassy(permission);
    }

    @Override
    public EssayAndUser ShowEssayDetail(Integer essayId) {
        // TODO Auto-generated method stub
        return eDao.FindEssayByEssayId(essayId);
    }

    @Override
    public Essay ShowEssayDetailNoUser(Integer essayId) {
        return eDao.FindEssayByEssayID(essayId);
    }

    @Override
    public int UpdateEssayPtcvr(Essay essay) {
        // TODO Auto-generated method stub
        return eMapper.updateByPrimaryKeySelective(essay);
    }

    @Override
    public int PublishEssay(Essay essay) {
        // TODO Auto-generated method stub
        return eMapper.insertSelective(essay);
    }

    @Override
    public List<Essay> ShowUsersEssay(Integer userId,Page page) {
        // TODO Auto-generated method stub
        return eDao.FindEssayByUser(userId,page);
    }

    @Override
    public Integer ShowUsersEssayCount(Integer userId) {
        Integer count=0;
        return eDao.FindEssayByUserCount(userId);
    }

    @Override
    public int DeleteEssay(Integer essayId) {
        // TODO Auto-generated method stub
        return eMapper.deleteByPrimaryKey(essayId);
    }

    @Override
    public Essay FindEssay(Integer essayId) {
        // TODO Auto-generated method stub
        return eMapper.selectByPrimaryKey(essayId);
    }

    @Override
    public List<EssayAndUser> ShowLimitEssayLogout(String permission, Page page) {
        // TODO Auto-generated method stub
        return eDao.findLimitEssay(permission, page);
    }

    @Override
    public int ShowLimitEssayLogoutCount(String permission) {
        return eDao.findLimitEssayCount(permission);
    }

    @Override
    public List<EssayAndUser> ShowLimitEssaySelect(String category, String permission, Page page) {
        // TODO Auto-generated method stub
        return eDao.findLimitEssaySelect(category, permission, page);
    }

    @Override
    public int ShowLimitEssaySelectCount(String category, String permission) {
        return eDao.findLimitEssaySelectCount(category,permission);
    }

    @Override
    public List<EssayAndUser> FindByCommentNumber(String startDate, String permission) {
        // TODO Auto-generated method stub
        return eDao.selectByCommenNumber(startDate, permission);
    }

    @Override
    public List<Essay> ShowUserEssayByDate(Integer userId, String permission) {
        // TODO Auto-generated method stub
        return eDao.selectByDate(userId, permission);
    }

    @Override
    public List<EssayAndUser> SearchResultLogin(String text,Page page) {
        // TODO Auto-generated method stub
        String permission = "B_self";
        return eDao.selectEssayBySearchLogin(text, permission,page);
    }

    @Override
    public int SearchResultLoginCount(String text) {
        String permission = "B_self";
        return eDao.selectEssayBySearchLoginCount(text,permission);
    }

    @Override
    public Integer ReturnEssayId(Essay essay) {
        // TODO Auto-generated method stub
        return eMapper.insertSelective1(essay);
    }

    @Override
    public List<EssayAndUser> ShowBuserEssay() {
        // TODO Auto-generated method stub
        String permission = "B_self";
        return eDao.selectBuserEssay(permission);
    }

    @Override
    public List<EssayAndUser> ShowBselfEssay() {
        // TODO Auto-generated method stub
        String permission = "B_self";
        return eDao.SelectBselfEssay(permission);
    }

    @Override
    public List<EssayAndUser> ShowLimitEssayLogin(String permission, Page page) {
        return eDao.findLimitEssayP(permission, page);
    }

    @Override
    public int ShowLimitEssayLoginCount(String permission) {
        return eDao.findLimitEssayPCount(permission);
    }

    @Override
    public List<EssayAndUser> FindByCommentNumberLimit(String startDate, String permission) {
        // TODO Auto-generated method stub
        return eDao.selectByCommenNumberLimit(startDate, permission);
    }

    @Override
    public List<EssayAndUser> ShowLimitEssaySelectBself(String category, String permission, Page page) {
        // TODO Auto-generated method stub
        return eDao.findLimitEssaySelectBself(category, permission, page);
    }

    @Override
    public int ShowLimitEssaySelectBselfCount(String category, String permission) {
        return eDao.findLimitEssaySelectBselfCount(category,permission);
    }

    @Override
    public List<EssayAndUser> FindEssayByCategoryAndPraiseLogout(String category, Page page) {
        String permission = "B_all";
        return eDao.selectEssayByCategoryAndPraiseLogout(category, permission, page);
    }

    @Override
    public int FindEssayByCategoryAndPraiseLogoutCount(String category) {
        String permission="B_all";
        return eDao.selectEssayByCategoryAndPraiseLogoutCount(category,permission);
    }

    @Override
    public List<EssayAndUser> FindEssayByCategoryAndPraiseLogin(String category, Page page) {
        String permission = "B_self";
        return eDao.selectEssayByCategoryAndPraiseLogin(category, permission, page);
    }

    @Override
    public int FindEssayByCategoryAndPraiseLoginCount(String category) {
        String permission = "B_self";
        return eDao.selectEssayByCategoryAndPraiseLoginCount(category,permission);
    }

    @Override
    public List<Essay> ShowUserEssayByDateLimit(Integer userId, String permission) {
        // TODO Auto-generated method stub
        return eDao.selectByDateLimit(userId, permission);
    }

    @Override
    public Essay FindEssayLimitLogout(Integer essayId, String permission) {
        // TODO Auto-generated method stub
        return eDao.FindEssayByEssayIdLimitLogout(essayId, permission);
    }

    @Override
    public Essay FindEssayLimitLogin(Integer essayId, String permission) {
        // TODO Auto-generated method stub
        return eDao.FindEssayByEssayIdLimitlogin(essayId, permission);
    }

    @Override
    public List<Essay> ShowUserEssayByDateNoLimit(Integer userId) {
        // TODO Auto-generated method stub
        return eDao.selectByDateNoLimit(userId);
    }

    @Override
    public List<EssayAndUser> SearchResultLogout(String text,Page page) {
        // TODO Auto-generated method stub
        String permission = "B_all";
        return eDao.selectEssayBySearchLogout(text, permission,page);
    }

    @Override
    public int SearchResultLogoutCount(String text) {
        String permission = "B_all";
        return eDao.selectEssayBySearchLogoutCount(text,permission);
    }

    @Override
    public Integer FindPublisher(Integer essayId) {
        // TODO Auto-generated method stub
        return eDao.selectuserId(essayId);
    }

    @Override
    public List<EssayAndUser> FindManagerViewEssay(Page page) {
        // TODO Auto-generated method stub
        PageReturn pageReturn = new PageReturn();
        page = pageReturn.ReturnPage(page);
        return eDao.selectManagerEssay(page);
    }

    @Override
    public List<EssayAndUser> FindEssayByPraiseLogout(Page page) {
        String permission = "B_all";
        return eDao.selectEssayByPraiseLogout(permission, page);
    }

    @Override
    public int FindEssayByPraiseLogoutCount() {
        String permission = "B_all";
        return eDao.selectEssayByPraiseLogoutCount(permission);
    }

    @Override
    public List<EssayAndUser> FindEssayByPraiseLogin(Page page) {
        String permission = "B_self";
        return eDao.selectEssayByPraiseLogin(permission, page);
    }

    @Override
    public int FindEssayByPraiseLoginCount() {
        String permission = "B_self";
        return eDao.selectEssayByPraiseLoginCount(permission);
    }

}
